<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const activeIndex = ref('1')

const handleSelect = (key: string) => {
  switch (key) {
    case '1':
      router.push('/')
      break
    case '2':
      router.push('/posts')
      break
    case '3':
      router.push('/market')
      break
    case '4':
      router.push('/profile')
      break
  }
}
</script>

<template>
  <div id="app">
    <!-- 导航栏 -->
    <el-header class="header">
      <div class="header-content">
        <div class="logo">
          <h2>GanstLaLa</h2>
        </div>
        <el-menu
          :default-active="activeIndex"
          class="nav-menu"
          mode="horizontal"
          @select="handleSelect"
        >
          <el-menu-item index="1">首页</el-menu-item>
          <el-menu-item index="2">GL论坛</el-menu-item>
          <el-menu-item index="3">跳蚤市场</el-menu-item>
          <el-menu-item index="4">个人主页</el-menu-item>
        </el-menu>
        <div class="user-actions">
          <el-button type="primary" @click="router.push('/login')">登录</el-button>
          <el-button @click="router.push('/register')">注册</el-button>
        </div>
      </div>
    </el-header>

    <!-- 主要内容区域 -->
    <div class="main-flex">
      <el-main class="main-content">
        <router-view />
      </el-main>
    </div>

    <!-- 页脚 -->
    <el-footer class="footer">
      <p>&copy; 2024 GanstLaLa. All rights reserved.</p>
    </el-footer>
  </div>
</template>

<style scoped>
#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0 16px;
  box-sizing: border-box;
}

.logo h2 {
  margin: 0;
  color: white;
  font-weight: bold;
  white-space: nowrap;
}

.nav-menu {
  background: transparent;
  border: none;
  flex: 1;
  display: flex;
  justify-content: center;
  margin: 0 16px;
}

.nav-menu .el-menu-item {
  color: white;
  font-weight: 500;
  padding: 0 20px;
  min-width: 100px;
  text-align: center;
}

.nav-menu .el-menu-item:hover,
.nav-menu .el-menu-item.is-active {
  background-color: rgba(255, 255, 255, 0.1);
  color: white;
}

.user-actions {
  display: flex;
  gap: 10px;
  white-space: nowrap;
}

.main-flex {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
}

.main-content {
  flex: 1 1 auto;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.footer {
  background-color: #f5f5f5;
  text-align: center;
  padding: 20px;
  color: #666;
}

@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 10px;
    padding: 10px 8px;
  }
  .nav-menu {
    margin: 0;
    width: 100%;
    justify-content: space-between;
  }
  .nav-menu .el-menu-item {
    padding: 0 10px;
    min-width: auto;
    font-size: 0.9em;
  }
  .user-actions {
    width: 100%;
    justify-content: center;
  }
  .main-content {
    padding: 5px 0 0 0;
  }
}
</style>
